package com.skywaregroup.arenal;

import java.util.Set;
import javax.persistence.*;
import javax.xml.bind.annotation.*;


@XmlRootElement(name="NHIFPack") 
@XmlAccessorType(XmlAccessType.NONE) 
@Entity
@Table(name="nhif_packs") 
public class NHIFPack {
	
	@Id 
	@Column(name="code", nullable=false) 
	public Integer code;
	
	@XmlElement(name="Code")
	public String getCode() {
		return String.format("%02d", this.code);
	}
	
	public void setCode(String s){
		if (!s.matches("^\\d{2}$")) {throw new IllegalArgumentException("Code must be 2-digits string.");}
		this.code = Integer.parseInt(s);
	}
	
	@Column(name="name")
	@XmlElement(name="Name")
	public String name;	
	
	@ManyToMany(targetEntity=NHIFExam.class, fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
	@JoinTable(name = "nhif_packs_exams", joinColumns = { 
			@JoinColumn(name = "nhif_pack_code", nullable = false, updatable = false) }, 
			inverseJoinColumns = { @JoinColumn(name = "nhif_exam_code", nullable = false, updatable = false) })
	@XmlElement(name="NHIFExam") 
	public Set<NHIFExam> exams;
	
}
